export function move(el) {
  el.onmousedown = function (e) {
    document.onselectstart = function () {
      return false
    }
    const disx = e.pageX - el.offsetLeft
    const disy = e.pageY - el.offsetTop
    if (e.preventDefault) {
      e.preventDefault()
    } else {
      e.returnValue = false
    }
    document.onmousemove = function (e) {
      let left = e.clientX - disx
      let top = e.clientY - disy

      if (left <= 0) {
        left = 5 // 设置成5是为了不离边缘太近
      } else if (left > document.documentElement.clientWidth - el.clientWidth) {
        // document.documentElement.clientWidth 屏幕的可视宽度
        left = document.documentElement.clientWidth - el.clientWidth - 5
      }
      if (top <= 0) {
        top = 5
      } else if (top > document.documentElement.clientHeight - el.clientHeight) {
        top = document.documentElement.clientHeight - el.clientHeight - 5
        console.log(document.documentElement.clientHeight, el.clientHeight)
      }
      el.style.left = left + 'px'
      el.style.top = top + 'px'
    }
    document.onmouseup = function () {
      document.onmousemove = document.onmouseup = null
    }
  }
}
export function stopMove(el) {
  el.onmousedown = function (e) {
    e.stopPropagation()
  }
}